package com.example.finallyjob.Controllers;

import com.example.finallyjob.entity.ArticleInfo;
import com.example.finallyjob.entity.Reply;
import com.example.finallyjob.service.OpenArticle;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@Api(description = "作品打开所需信息(评论、作品信息、作者信息)")
@RestController
public class ArticleOpenController {
    @Autowired
    OpenArticle openArticle;

    @ApiOperation(value = "读取文章作品和作者信息",notes = "返回作品信息和作者信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "num", value = "作品文件的编号", required = true, dataType = "String"),
    })
    @PostMapping("/searchInfo/{num}")
    public ArticleInfo searchInfo(@PathVariable("num") String num){
        return openArticle.searchInfo(num);
    }

    @ApiOperation(value = "读取视频和作者信息",notes = "返回视频信息和作者信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "num", value = "作品文件的编号", required = true, dataType = "String"),
    })
    @PostMapping("/videoInfo/{num}")
    public ArticleInfo videoInfo(@PathVariable("num") String num){
        return openArticle.videoInfo(num);
    }

    @ApiOperation(value = "读取作品评论和回复",notes = "返回回复和回复的评论")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "num", value = "作品文件的编号", required = true, dataType = "String"),
    })
    @PostMapping("/LoadComments/{num}")
    public List<Reply> LoadComments(@PathVariable("num") String num){
        return openArticle.LoadComments(num);
    }


    @ApiOperation(value = "读取文章作品")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "num", value = "作品文件的编号", required = true, dataType = "String"),
    })
    @PostMapping("/upArticle/{num}")
    public StringBuilder upArticle(@PathVariable("num") String num) throws IOException {
        return openArticle.openArtcle(num);
    }

}
